﻿using Sustainalytics.Entities;
using System;

namespace Sustainalytics.Accounts.Service.Models
{
    public class UserDto
    {
        public Guid Id { get; set; }
        public string FullName { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string MiddleName { get; set; }
        public string Email { get; set; }
        public string Status { get; set; }
        public string Account { get; set; }
        public Guid? AccountId { get; set; }
        public DateTime PasswordExpirationDate { get; set; }
        public DateTime? LastSyncWithCRM { get; set; }

        public bool IsFakeIpUser { get; set; }

        private UserDto() { }

        public static UserDto CreateComplete(User user, DateTime passwordExpirationDate)
        {
            if (user == null)
                throw new ArgumentNullException("user", "User cannot be null.");

            return new UserDto()
            {
                Id = user.Id,
                Account = user.Account,
                AccountId = user.AccountId,
                FirstName = user.FirstName,
                FullName = user.FullName,
                LastName = user.LastName,
                LastSyncWithCRM = user.SyncOn,
                MiddleName = user.MiddleName,
                PasswordExpirationDate = passwordExpirationDate,
                Status = user.Status.ToString(),
                Email = user.Email,
                IsFakeIpUser = user.IsFakeIpUser
            };
        }

        public static object CreateIdFullName(User user)
        {
            if (user == null)
                throw new ArgumentNullException("user", "User cannot be null.");

            return new 
            {
                Id = user.Id,
                FullName = user.FullName
            };
        }

        public static object CreateIdFullNameEmailAccountAccessDateStatus(User user)
        {
            if (user == null)
                throw new ArgumentNullException("user", "User cannot be null.");

            return new
            {
                Id = user.Id,
                FullName = user.FullName,
                Email = user.Email,
                Account = user.Account,
                LastAccessDate = "", //LastAccessDate not yet implemented
                Status = user.Status.ToString(),
                user.IsFakeIpUser
            };
        }

        public static object CreateIdFullNameEmailStatus(User user)
        {
            if (user == null)
                throw new ArgumentNullException("user", "User cannot be null.");

            return new
            {
                Id = user.Id,
                FullName = user.FullName,
                Email = user.Email,
                Status = user.Status.ToString(),
                user.IsFakeIpUser
            };
        }
    }
}
